package com.yitongmao.util;

import com.yitongmao.common.reminder.ReaderApplication;
import com.yitongmao.core.cache.ACache;

import java.util.Map;
import java.util.TreeMap;

public class SignUtil {
    //    KEY  --可保存与.so文件
    public static final String KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";

    public static String signList(String timestamp, String nonce) {
        Map<String, String> map = new TreeMap<>();
        map.put("nonce", nonce);
        map.put("timestamp", timestamp);
        return Md5Utils.createSign(map, KEY);
    }
    public static String sign(Map<String, String> map) {
        return Md5Utils.createSign(map, KEY);
    }
    public static String signLogin(String nonce, String timestamp) {
        String userName = ACache.get(ReaderApplication.applicationContext).getAsString("userName");
        String pwd = ACache.get(ReaderApplication.applicationContext).getAsString("pwd");
        MD5Builder md5Builder=new MD5Builder();
        Map<String, String> map = new TreeMap<>();
        map.put("userName", userName);
        map.put("pwd", md5Builder.getMD5Str(pwd));
        map.put("nonce", nonce);
        map.put("timestamp", timestamp);
        return Md5Utils.createSign(map, KEY);
    }

}
